package com.mineoj.judge.codesandbox.impl;
import com.mineoj.judge.codesandbox.CodeSandbox;
import com.mineoj.judge.codesandbox.model.ExecuteCodeRequest;
import com.mineoj.judge.codesandbox.model.ExecuteCodeResponse;
import com.mineoj.model.dto.questionsubmit.JudgeInfo;
import com.mineoj.model.enums.JudgeInfoMessageEnum;
import com.mineoj.model.enums.QuestionSubmitStatusEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * 示例代码沙箱（仅为了跑通业务流程）
 */
public class ExampleCodeSandbox implements CodeSandbox {

    @Override
    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
        List<String> inputList = executeCodeRequest.getInputList();
        ExecuteCodeResponse executeCodeResponse = new ExecuteCodeResponse();
        List<String> outputList = new ArrayList<>();
        for (String input : inputList){
            // 以空格分割字符串
            String[] split = input.split(" ");
            Integer num1 = Integer.parseInt(split[0]);
            Integer num2 = Integer.parseInt(split[1]);
            outputList.add(String.valueOf(num1 + num2));
            System.out.println(split[0] + "+ " + split[1] + " = " + (num1 + num2));
        }
        executeCodeResponse.setOutputList(outputList);
        executeCodeResponse.setStatus(QuestionSubmitStatusEnum.SUCCEED.getValue());
        JudgeInfo judgeInfo = new JudgeInfo();
        judgeInfo.setMessage(JudgeInfoMessageEnum.ACCEPTED.getText());
        judgeInfo.setMemory(100L);
        judgeInfo.setTime(100L);
        executeCodeResponse.setJudgeInfo(judgeInfo);
        System.out.println(executeCodeResponse);
        return executeCodeResponse;
    }



}
